﻿CREATE PROCEDURE [dbo].[ew_sp_install_configurations]
    @uid_configuration_id   UNIQUEIDENTIFIER, 
    @vc_name                VARCHAR(512), 
    @vc_description         VARCHAR(1024) = NULL, 
    @xml_value_1            XML           = NULL,
    @xml_value_2            XML           = NULL,
    @xml_value_3            XML           = NULL,
    @xml_value_4            XML           = NULL,
    @xml_value_5            XML           = NULL,
    @xml_value_6            XML           = NULL,
    @xml_value_7            XML           = NULL,
    @xml_value_8            XML           = NULL,
    @xml_value_9            XML           = NULL,
    @dt_datetime            DATETIME,
    @nvc_user               NVARCHAR(1024)
AS
    IF NOT EXISTS (SELECT 1 FROM ew_tbl_configurations WHERE ew_uid_configuration_id = @uid_configuration_id)
    BEGIN
        INSERT ew_tbl_configurations (
            ew_uid_configuration_id, 
            ew_vc_name, 
            ew_vc_description, 
            ew_xml_value_1, 
            ew_xml_value_2, 
            ew_xml_value_3, 
            ew_xml_value_4, 
            ew_xml_value_5, 
            ew_xml_value_6, 
            ew_xml_value_7, 
            ew_xml_value_8, 
            ew_xml_value_9, 
            ew_dt_created, 
            ew_nvc_created_by, 
            ew_dt_modified, 
            ew_nvc_modified_by)
        VALUES (
            @uid_configuration_id, 
            @vc_name, 
            @vc_description, 
            @xml_value_1, 
            @xml_value_2, 
            @xml_value_3, 
            @xml_value_4, 
            @xml_value_5, 
            @xml_value_6, 
            @xml_value_7, 
            @xml_value_8, 
            @xml_value_9, 
            @dt_datetime, 
            @nvc_user, 
            @dt_datetime, 
            @nvc_user)
    END
    ELSE
    BEGIN
        UPDATE ew_tbl_configurations SET
            ew_vc_name         = @vc_name, 
            ew_vc_description  = @vc_description, 
            ew_xml_value_1     = @xml_value_1, 
            ew_xml_value_2     = @xml_value_2, 
            ew_xml_value_3     = @xml_value_3, 
            ew_xml_value_4     = @xml_value_4, 
            ew_xml_value_5     = @xml_value_5, 
            ew_xml_value_6     = @xml_value_6, 
            ew_xml_value_7     = @xml_value_7, 
            ew_xml_value_8     = @xml_value_8, 
            ew_xml_value_9     = @xml_value_9, 
            ew_dt_created      = @dt_datetime, 
            ew_nvc_created_by  = @nvc_user, 
            ew_dt_modified     = @dt_datetime, 
            ew_nvc_modified_by = @nvc_user
        WHERE ew_uid_configuration_id = @uid_configuration_id
    END
RETURN 0
